package srw;

import java.util.HashMap;
import java.util.Vector;

import utils.XMLUtils;
/**
 * Dictionary is not in use in last version
 * there are {@link LexParser} and handlers to correspond sentence word to list of appropriate objects {@link Word}
 *
 */
public class Dictionary {

	private static Dictionary _Self;
	private HashMap<String, Vector<Word>> _dictionary;
	
	/**
	 * constructor
	 * @param dictionary hash map which corresponds sentence word to list of appropriate objects {@link Word}
	 */
	private Dictionary(HashMap<String, Vector<Word>> dictionary) {
		_dictionary = dictionary;
	}
	
	/**
	 * get the instance of the Dictionary class
	 * @return instance of the singleton Dictionary
	 */
	public static Dictionary instance() {
		if (_Self == null) {
            _Self = createInstance();
        }
        return _Self;
	}
	
	/**
	 * load dictionary map from file and create Dictionary instance
	 * @return Dictionary instance
	 */
	private static Dictionary createInstance() {
		System.err.println("CREATE DICTIONARY");
		Dictionary dictionary = null;
		HashMap<String, Vector<Word>> dictionaryMap = XMLUtils.loadDictionaryMapFromXML(MainFrame._FilesPath + MainFrame._DictionaryFile);
		if (dictionaryMap != null) {
			dictionary = new Dictionary(dictionaryMap);
		}
		return dictionary;
		
	}
	
	/** 
	 * get list of {@link Word} objects by key
	 * @param key sentence word
	 * @return list of {@link Word} objects
	 */
	public Vector<Word> getWords(String key) {
		return _dictionary.get(key);
	}
	
}
